package com.csdj.t309springboot.service;
import com.csdj.t309springboot.entity.IntegralRecord;
import com.csdj.t309springboot.mapper.IntegralRecordMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
/**
 * <p>
 * 积分记录表 Integral record 服务实现类
 * </p>
 *
 * @author 谭湛宇
 * @since 2022-01-13
 */
@Service
public class IntegralRecordService extends ServiceImpl<IntegralRecordMapper, IntegralRecord> implements IIntegralRecordService {
    @Resource
    private IntegralRecordMapper integralRecordMapper;

    @Transactional(rollbackFor = Exception.class)//针对检查异常(非运行时异常)进行事务回滚;
    //因为Spring的默认的事务规则是遇到运行异常（RuntimeException及其子类）和程序错误（Error）才会进行事务回滚，显然SQLException并不属于这个范围
    public int insert(IntegralRecord integralRecord){
        int insert = integralRecordMapper.insert(integralRecord);
        //模拟异常
//        int i = insert / 0;
        return insert;
    }

    public List<IntegralRecord> getIntegralRecordListByUserId(int userId){
        return integralRecordMapper.findIntegralRecordListByUserId(userId);
    }
    public IntegralRecord getIntegralRecordInfoByUserId(int userId){
        return integralRecordMapper.findIntegralRecordInfoByUserId(userId);
    }


}
